package synchronizedTest;

/**
 * 
 * 
 * @author lcx
 *
 */
public class SynchronizedBlockTest {


	public  void synchronizedBlock(int i)
	{
		synchronized(this)
		{
			System.out.println(i+"  block  start...");
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(i+"  block  start...");
		}
	}


	public static void main(String[] args) {
		final SynchronizedBlockTest test=new SynchronizedBlockTest();
		Thread td1=new Thread()
		{
			int i=1;
			@Override
			public void run()
			{
				while(i++<5)
					test.synchronizedBlock(i);
			}
		};

		Thread td2=new Thread()
		{
			@Override
			public void run()
			{
				int i=5;
				while(i++<10)
					test.synchronizedBlock(i);
			}
		};

		td1.start();
		td2.start();
	}


}


